using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class DistanceField2DEditor : Editor
{
    [MenuItem("Assets/DistanceField/GenDF")]
    public static void CreateDFInside()
    {
        var tex = Selection.activeObject as Texture2D;

        if (tex != null)
        {
            var output = DistanceField2D.GenerateDF(tex, TextureFormat.RGBAFloat);

            string path = AssetDatabase.GetAssetPath(tex);

            int index = path.LastIndexOf('.');

            path = path.Substring(0,index);

            byte[] data = output.EncodeToEXR();

            System.IO.File.WriteAllBytes(path + "_df.exr", data);

            AssetDatabase.Refresh();
        }
    }

    [MenuItem("Assets/DistanceField/GenSDF")]
    public static void CreateSDF()
    {
        var tex = Selection.activeObject as Texture2D;

        if (tex != null)
        {
            var output = DistanceField2D.GenerateSDF(tex, TextureFormat.RGBAFloat);

            string path = AssetDatabase.GetAssetPath(tex);

            int index = path.LastIndexOf('.');

            path = path.Substring(0, index);

            byte[] data = output.EncodeToEXR();

            System.IO.File.WriteAllBytes(path + "_sdf.exr", data);

            AssetDatabase.Refresh();
        }
    }
}
